home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-03 / qbasicpg.zip / COINS2.BAS < prev    next >
BASIC Source File  |  1989-08-31  |  2KB  |  62 lines

  1. ' COINS2.BAS
  2. ' This program uses the WRITE# statement to send coin-collection
  3. '   information to a sequential file and INPUT# to display it.
  4.  
  5. ' open file in APPEND mode so that previous contents won't be overwritten
  6.  
  7. OPEN "COINS.TXT" FOR APPEND AS #1  ' open file in current drive/dir
  8.  
  9. CLS
  10.  
  11. PRINT "This program stores coin-collection information on disk in a"
  12. PRINT "file named COINS.TXT.  Enter coin data and type END to quit."
  13. PRINT
  14.  
  15. DO WHILE (country$ <> "END")       ' until the user types END...
  16.  
  17. ' get coin-collection info from user and write it to the open file
  18.  
  19.     INPUT "What country is the coin from?  ", country$
  20.     IF (country$ <> "END") THEN    ' if country$ is END don't write
  21.         INPUT "What is the value of the coin?  ", value$
  22.         INPUT "What is the name of the coin?   ", coinName$
  23.         INPUT "What year was the coin minted?  ", year%
  24.  
  25.         WRITE #1, country$, value$, coinName$, year%  ' send fields
  26.     END IF
  27.     PRINT                          ' print blank lines between coins
  28.  
  29. LOOP
  30.  
  31. CLOSE #1                           ' close the file
  32.  
  33. ' wait for the user to press Enter to continue
  34.  
  35. INPUT "Press Enter to see the contents of your coin collection", dummy$
  36. CLS                                ' start with a fresh screen
  37.  
  38. ' open file in INPUT mode so that contents can be read by program
  39.  
  40. OPEN "COINS.TXT" FOR INPUT AS #1   ' file is in current drive/dir
  41.  
  42. ' display header for tabular collection information
  43.  
  44. PRINT "Coin origin      Coin value    Coin name     Year minted"
  45. PRINT "--------------------------------------------------------"
  46. PRINT
  47.  
  48. ' initialize formatting template for use with PRINT USING
  49.  
  50. tmp$ = "\             \  \          \  \          \  ####"
  51.  
  52. ' while the end of the file has not been reached, assign file
  53. '   items to variables and print them out
  54.  
  55. DO WHILE (NOT EOF(1))
  56.     INPUT #1, country$, value$, coinName$, year%
  57.     PRINT USING tmp$; country$; value$; coinName$; year%
  58. LOOP
  59.  
  60. CLOSE #1                           ' close the file
  61.  
  62.